package com.xms.config;

import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * <p>
 * spring cache key generator
 * </p>
 *
 * @author migo
 * @since 2021/10/1
 */
@Component
public class CacheKeyGenerator implements KeyGenerator {
    @Override
    public Object generate(Object target, Method method, Object... params) {
        return target.getClass().getName() + "." + method.getName() + "_" +
                Stream.of(params).map(Object::toString).collect(Collectors.joining(","));
    }
}

